package com.mario.domain;

import java.io.Serializable;
import java.sql.Timestamp;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;

import org.hibernate.annotations.GenericGenerator;

@MappedSuperclass
public class MySerializable implements Serializable {

	private static final long serialVersionUID = 3491455058184331150L;
	
	//*********************************************************
    // Attributes
    //*********************************************************
    
	@Id
    @GenericGenerator(name="generator", strategy="increment")
    @GeneratedValue(generator="generator")
    @Column(name="oid")
	private long oid;
	
	@Column(name="object_time")
    private Timestamp objectTime;
    
	//*********************************************************
    // Constructor
    //*********************************************************
    
	public MySerializable() {
		super();
		this.objectTime = getNewObjectTime();
	}

	public MySerializable(Timestamp objectTime) {
		super();
		this.objectTime = objectTime;
	}
    
    //*********************************************************
    // Getters and Setters
    //*********************************************************
    
    public long getOid() {
		return oid;
	}

	public void setOid(long oid) {
		this.oid = oid;
	}

	public Timestamp getObjectTime() {
		return objectTime;
	}

	public void setObjectTime(Timestamp objectTime) {
		this.objectTime = objectTime;
	}
	
    //*********************************************************
    // Methods
    //*********************************************************
	
	@Override
	public boolean equals(Object obj) {
		MySerializable object = (MySerializable) obj;
		return Long.valueOf(this.oid).equals(Long.valueOf(object.oid));
	}
	
	@Override
	public int hashCode() {
		// TODO
		return super.hashCode();
	}
	
    
	private Timestamp getNewObjectTime() {
		return new Timestamp(System.currentTimeMillis());
	}

}
